namespace CIS.UserCheck
{
    using CISLib;
    using System;
    using System.Collections;
    using System.Data;
    using System.IO;
    using System.Text;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public class CheckUserCountTeamPage : Page
    {
        protected Button addCatBtn;
        protected Button addProvinceBtn;
        protected Button addRoleBtn;
        protected DropDownList catDdl;
        protected ListBox catLb;
        protected Button delCatBtn;
        protected Button delProvinceBtn;
        protected Button delRoleBtn;
        protected Table KPISumTable;
        protected Label Label7;
        protected LinkButton lkbDown;
        protected UserPrincipal Principal = null;
        protected DropDownList provinceDdl;
        protected ListBox provinceLb;
        protected DropDownList roleDdl;
        protected ListBox roleLb;
        protected Button searchBtn;
        protected DropDownList YQDdl;

        private void addCatBtn_Click(object sender, EventArgs e)
        {
            if (this.catDdl.SelectedItem.Text == "Root")
            {
                this.catLb.Items.Clear();
                this.catLb.DataSource = ManageCAT.GetCAT(new Guid("06BA8C26-B1C9-4415-A6EC-1CF5CE99BF15"));
                this.catLb.DataTextField = "CATGroupName";
                this.catLb.DataValueField = "CATGroupId";
                this.catLb.DataBind();
                this.catLb.Items.RemoveAt(0);
            }
            else
            {
                ListItem tmpItem = new ListItem();
                tmpItem.Text = this.catDdl.SelectedItem.Text;
                tmpItem.Value = this.catDdl.SelectedItem.Value;
                if (!this.IsExistItem(tmpItem, this.catLb))
                {
                    this.catLb.Items.Add(tmpItem);
                }
            }
        }

        private void addProvinceBtn_Click(object sender, EventArgs e)
        {
            if (this.provinceDdl.SelectedItem.Text == "All")
            {
                this.provinceLb.Items.Clear();
                this.provinceLb.DataSource = ManageProvince.GetProvince(new Guid("06BA8C26-B1C9-4415-A6EC-1CF5CE99BF15"));
                this.provinceLb.DataTextField = "RegionName";
                this.provinceLb.DataValueField = "RegionId";
                this.provinceLb.DataBind();
                this.provinceLb.Items.RemoveAt(0);
            }
            else
            {
                ListItem tmpItem = new ListItem();
                tmpItem.Text = this.provinceDdl.SelectedItem.Text;
                tmpItem.Value = this.provinceDdl.SelectedItem.Value;
                if (!this.IsExistItem(tmpItem, this.provinceLb))
                {
                    this.provinceLb.Items.Add(tmpItem);
                }
            }
        }

        private void addRoleBtn_Click(object sender, EventArgs e)
        {
            ListItem tmpItem = new ListItem();
            tmpItem.Text = this.roleDdl.SelectedItem.Text;
            tmpItem.Value = this.roleDdl.SelectedItem.Value;
            if (!this.IsExistItem(tmpItem, this.roleLb))
            {
                this.roleLb.Items.Add(tmpItem);
            }
        }

        private void delCatBtn_Click(object sender, EventArgs e)
        {
            try
            {
                this.catLb.Items.Remove(this.catLb.Items[this.catLb.SelectedIndex]);
            }
            catch
            {
            }
        }

        private void delProvinceBtn_Click(object sender, EventArgs e)
        {
            try
            {
                this.provinceLb.Items.Remove(this.provinceLb.Items[this.provinceLb.SelectedIndex]);
            }
            catch
            {
            }
        }

        private void delRoleBtn_Click(object sender, EventArgs e)
        {
            try
            {
                this.roleLb.Items.Remove(this.roleLb.Items[this.roleLb.SelectedIndex]);
            }
            catch
            {
            }
        }

        private int GetCustomerUpdateNum(Guid customerId)
        {
            string selectYQ = this.YQDdl.SelectedItem.Text;
            string strYear = selectYQ.Substring(0, 2);
            string strQ = selectYQ.Substring(3, 1);
            return ManageCheckUser.GetCustomerUpdateNumInLog(customerId, strYear, strQ);
        }

        private int GetImportCustomerCountNumViaCustomerCompany(Guid catId, Guid provinceId)
        {
            Guid[] companyIdAry = ManageCheckUser.GetCompanyIdViaCatIdAndProvinceId(catId, provinceId);
            int ImportCustomerCountNum = 0;
            for (int i = 0; i < companyIdAry.Length; i++)
            {
                ImportCustomerCountNum += ManageCheckUser.GetImportCustomerCountViaIdInOrgTree(companyIdAry[i]);
            }
            return ImportCustomerCountNum;
        }

        private void GetUserCountTeam()
        {
            ArrayList list = new ArrayList();
            for (int x = 0; x < this.roleLb.Items.Count; x++)
            {
                Role tmpRole = new Role();
                tmpRole.RoleName = this.roleLb.Items[x].Text;
                tmpRole.RoleId = new Guid(this.roleLb.Items[x].Value);
                list.Add(tmpRole);
            }
            for (int i = 0; i < this.catLb.Items.Count; i++)
            {
                for (int x = 0; x < this.provinceLb.Items.Count; x++)
                {
                    Guid[] customerIdAry = ManageCustomer.GetCustomerIdAryInCustomerBasicInfo(new Guid(this.catLb.Items[i].Value), new Guid(this.provinceLb.Items[x].Value), new Guid("06BA8C26-B1C9-4415-A6EC-1CF5CE99BF15"));
                    int updateCount_Inspirit = 0;
                    int userCustomerInfoCount = 0;
                    for (int j = 0; j < customerIdAry.Length; j++)
                    {
                        int emptyCount = 0;
                        CustomerBasicInfo customerBasicInfo = ManageCustomer.GetCustomerBasicInfoViaId(customerIdAry[j]);
                        emptyCount = (customerBasicInfo.Name == "") ? emptyCount : (emptyCount + 1);
                        emptyCount = (customerBasicInfo.Gender.Trim() == "") ? emptyCount : (emptyCount + 1);
                        emptyCount = (customerBasicInfo.Title == "") ? emptyCount : (emptyCount + 1);
                        emptyCount = (customerBasicInfo.MailAdd == "") ? emptyCount : (emptyCount + 1);
                        emptyCount = (customerBasicInfo.Level == 0) ? emptyCount : (emptyCount + 1);
                        emptyCount = (customerBasicInfo.Depart == "") ? emptyCount : (emptyCount + 1);
                        emptyCount = (customerBasicInfo.CustomerDefId.ToString() == "11111111-1111-1111-1111-111111111111") ? emptyCount : (emptyCount + 1);
                        emptyCount = ManageProduct.IsExitProductInCustomerProductViaId(customerBasicInfo.CustomerId) ? (emptyCount + 1) : emptyCount;
                        if (ManageCustomer.IsExistSameCoustomerPersonalInfo(customerIdAry[j]))
                        {
                            CustomerPersonalInfo customerPersonalInfo = ManageCustomer.GetCustomerPersonalInfoViaId(customerIdAry[j]);
                            emptyCount = (customerPersonalInfo.BirthDate.ToString() == "1800-1-1 0:00:00") ? emptyCount : (emptyCount + 1);
                            emptyCount = (customerPersonalInfo.BirthPlace == "\0\0\0\0") ? emptyCount : (emptyCount + 1);
                            emptyCount = (customerPersonalInfo.FamilyAdd == "\0\0\0\0") ? emptyCount : (emptyCount + 1);
                            emptyCount = (customerPersonalInfo.RelocationAdd == "\0\0\0\0") ? emptyCount : (emptyCount + 1);
                            emptyCount = (customerPersonalInfo.Mobile == "\0\0\0\0") ? emptyCount : (emptyCount + 1);
                            emptyCount = (customerPersonalInfo.Weight == "\0\0\0\0") ? emptyCount : (emptyCount + 1);
                            emptyCount = (customerPersonalInfo.Height == "\0\0\0\0") ? emptyCount : (emptyCount + 1);
                            emptyCount = (customerPersonalInfo.SpecicalHobbies == "\0\0\0\0") ? emptyCount : (emptyCount + 1);
                        }
                        if (ManageCheckUser.IsExistCustomerPreferenceInfoViaId(customerIdAry[j]))
                        {
                            emptyCount++;
                        }
                        if (ManageCustomer.IsExistSameCoustomerHealthInfo(customerIdAry[j]))
                        {
                            CustomerHealth customerHealth = ManageCustomer.GetCustomerHealthViaId(customerIdAry[j]);
                            emptyCount = (customerHealth.HealthStatus == 3) ? emptyCount : (emptyCount + 1);
                            emptyCount = (customerHealth.Eyesight == 3) ? emptyCount : (emptyCount + 1);
                            emptyCount = (customerHealth.MajorOperation == "\0\0\0\0") ? emptyCount : (emptyCount + 1);
                            emptyCount = (customerHealth.SpecialDisease == "\0\0\0\0") ? emptyCount : (emptyCount + 1);
                            emptyCount = (customerHealth.Allergy == "\0\0\0\0") ? emptyCount : (emptyCount + 1);
                        }
                        if (ManageCustomer.IsExistSameCoustomerCostumeInfo(customerIdAry[j]))
                        {
                            CustomerCostumeInfo customerCostumeInfo = ManageCustomer.GetCustomerCostumeInfoViaId(customerIdAry[j]);
                            emptyCount = (customerCostumeInfo.BrandPre == "\0\0\0\0") ? emptyCount : (emptyCount + 1);
                            emptyCount = (customerCostumeInfo.HipMeasurement == "\0\0\0\0") ? emptyCount : (emptyCount + 1);
                            emptyCount = (customerCostumeInfo.NeckMeasurement == "\0\0\0\0") ? emptyCount : (emptyCount + 1);
                            emptyCount = (customerCostumeInfo.ShoesSize == "\0\0\0\0") ? emptyCount : (emptyCount + 1);
                        }
                        if (ManageCustomer.IsExistSameCustomerStudyExperienceInfo(customerIdAry[j]))
                        {
                            emptyCount++;
                        }
                        if (ManageCustomer.IsExistSameCustomerWorkExperienceInfo(customerIdAry[j]))
                        {
                            emptyCount++;
                        }
                        if (ManageCustomer.IsExistSameCustomerASBContractInfo(customerIdAry[j]))
                        {
                            emptyCount++;
                        }
                        if (ManageCustomer.IsExistSameCustomerEVMeetingInfo(customerIdAry[j]))
                        {
                            emptyCount++;
                        }
                        if (ManageCustomer.IsExistSameCustomerVisitingAbroadInfo(customerIdAry[j]))
                        {
                            emptyCount++;
                        }
                        if (ManageCustomer.IsExistSameCustomerASBEventsInfo(customerIdAry[j]))
                        {
                            emptyCount++;
                        }
                        if (ManageCustomer.IsExistSameCustomerEventsInfo(customerIdAry[j]))
                        {
                            emptyCount++;
                        }
                        if (ManageCustomer.IsExistSameCustomerResponsibleStaffInfo(customerIdAry[j]))
                        {
                            emptyCount++;
                        }
                        if (ManageCustomer.IsExistSameCustomerASBReceptionInfo(customerIdAry[j]))
                        {
                            emptyCount++;
                        }
                        userCustomerInfoCount += emptyCount;
                        updateCount_Inspirit += this.GetCustomerUpdateNum(customerIdAry[j]);
                    }
                    int userImportCustomerNumCount = 0;
                    int userImportCustomerNumAllCount = 0;
                    int userCustomerNumAllCount = 0;
                    ArrayList companyIdAry = new ArrayList();
                    if (customerIdAry.Length > 0)
                    {
                        for (int s = 0; s < customerIdAry.Length; s++)
                        {
                            int isExist = 0;
                            Guid tmpId = new Guid();
                            tmpId = ManageCheckUser.GetCompanyIdViaCustomerId(customerIdAry[s]);
                            for (int y = 0; y < companyIdAry.Count; y++)
                            {
                                if (((Guid) companyIdAry[y]) == tmpId)
                                {
                                    isExist = 1;
                                }
                            }
                            if (isExist == 0)
                            {
                                companyIdAry.Add(tmpId);
                            }
                        }
                        for (int z = 0; z < customerIdAry.Length; z++)
                        {
                            for (int w = 0; w < companyIdAry.Count; w++)
                            {
                                if (ManageCheckUser.IsExistImportCustomerInKPI((Guid) companyIdAry[w], ManageCheckUser.GetCustomerNameViaCustomerId(customerIdAry[z])))
                                {
                                    userImportCustomerNumCount++;
                                }
                            }
                        }
                    }
                    for (int v = 0; v < companyIdAry.Count; v++)
                    {
                        int tmpImportCustomerNumAllCount = ManageCheckUser.GetImportCustomerCountViaIdInOrgTree((Guid) companyIdAry[v]);
                        userImportCustomerNumAllCount += tmpImportCustomerNumAllCount;
                    }
                    userCustomerNumAllCount = customerIdAry.Length;
                    double fillInInfoCount = 0.0;
                    double updateCount = 0.0;
                    if (customerIdAry.Length > 0)
                    {
                        fillInInfoCount = Math.Round(Convert.ToDouble(userCustomerInfoCount), 2);
                        updateCount = Math.Round(Convert.ToDouble(updateCount_Inspirit), 2);
                    }
                    KPI sumKPI = new KPI();
                    sumKPI.FillInInfoCount = fillInInfoCount;
                    sumKPI.FillInImportCustomerCount = userImportCustomerNumCount;
                    sumKPI.AllImportCustomerCount = userImportCustomerNumAllCount;
                    sumKPI.AllCustomerCount = userCustomerNumAllCount;
                    sumKPI.UpdateCount_Inspirit = updateCount;
                    TableRow itemRow = new TableRow();
                    TableCell itemCell = new TableCell();
                    TableCell itemCellP = new TableCell();
                    itemCell.CssClass = "cell";
                    itemCell.Width = Unit.Pixel(0x23);
                    itemCell.Text = this.catLb.Items[i].Text;
                    itemRow.Cells.Add(itemCell);
                    itemCellP.CssClass = "cell";
                    itemCellP.Width = Unit.Pixel(40);
                    itemCellP.Text = this.provinceLb.Items[x].Text;
                    itemRow.Cells.Add(itemCellP);
                    TableCell blankItemCell1 = new TableCell();
                    blankItemCell1.CssClass = "cell";
                    blankItemCell1.Width = Unit.Pixel(50);
                    blankItemCell1.Text = sumKPI.FillInInfoCount.ToString();
                    itemRow.Cells.Add(blankItemCell1);
                    TableCell blankItemCell2 = new TableCell();
                    blankItemCell2.CssClass = "cell";
                    blankItemCell2.Width = Unit.Pixel(50);
                    blankItemCell2.Text = Convert.ToString((int) (sumKPI.AllCustomerCount * 0x23));
                    itemRow.Cells.Add(blankItemCell2);
                    TableCell blankItemCell3 = new TableCell();
                    blankItemCell3.CssClass = "cell";
                    blankItemCell3.Width = Unit.Pixel(50);
                    blankItemCell3.Text = sumKPI.FillInImportCustomerCount.ToString();
                    itemRow.Cells.Add(blankItemCell3);
                    TableCell blankItemCell4 = new TableCell();
                    blankItemCell4.CssClass = "cell";
                    blankItemCell4.Width = Unit.Pixel(50);
                    blankItemCell4.Text = this.GetImportCustomerCountNumViaCustomerCompany(new Guid(this.catLb.Items[i].Value), new Guid(this.provinceLb.Items[x].Value)).ToString();
                    itemRow.Cells.Add(blankItemCell4);
                    TableCell blankItemCell5 = new TableCell();
                    blankItemCell5.CssClass = "cell";
                    blankItemCell5.Width = Unit.Pixel(50);
                    blankItemCell5.Text = sumKPI.AllCustomerCount.ToString();
                    itemRow.Cells.Add(blankItemCell5);
                    TableCell blankItemCell6 = new TableCell();
                    blankItemCell6.CssClass = "cell";
                    blankItemCell6.Width = Unit.Pixel(50);
                    blankItemCell6.Text = sumKPI.UpdateCount_Inspirit.ToString();
                    itemRow.Cells.Add(blankItemCell6);
                    this.KPISumTable.Rows.Add(itemRow);
                }
            }
        }

        private void InitializeComponent()
        {
            this.addCatBtn.Click += new EventHandler(this.addCatBtn_Click);
            this.delCatBtn.Click += new EventHandler(this.delCatBtn_Click);
            this.addProvinceBtn.Click += new EventHandler(this.addProvinceBtn_Click);
            this.delProvinceBtn.Click += new EventHandler(this.delProvinceBtn_Click);
            this.addRoleBtn.Click += new EventHandler(this.addRoleBtn_Click);
            this.delRoleBtn.Click += new EventHandler(this.delRoleBtn_Click);
            this.searchBtn.Click += new EventHandler(this.searchBtn_Click);
            this.lkbDown.Click += new EventHandler(this.lkbDown_Click);
            base.Load += new EventHandler(this.Page_Load);
        }

        private void InitPage()
        {
            this.YQDdl.DataSource = KPIHelper.BuildLastFourYearQuarters(4);
            this.YQDdl.DataBind();
            this.InitTableTitle();
            this.provinceDdl.Items.Clear();
            this.provinceDdl.DataSource = ManageProvince.GetProvince(new Guid("06BA8C26-B1C9-4415-A6EC-1CF5CE99BF15"));
            this.provinceDdl.DataTextField = "RegionName";
            this.provinceDdl.DataValueField = "RegionId";
            this.provinceDdl.DataBind();
            this.catDdl.Items.Clear();
            this.catDdl.DataSource = ManageCAT.GetCAT(new Guid("06BA8C26-B1C9-4415-A6EC-1CF5CE99BF15"));
            this.catDdl.DataTextField = "CATGroupName";
            this.catDdl.DataValueField = "CATGroupId";
            this.catDdl.DataBind();
            this.roleDdl.Items.Clear();
            this.roleDdl.DataSource = ManageRole.GetRole(new Guid("06BA8C26-B1C9-4415-A6EC-1CF5CE99BF15"));
            this.roleDdl.DataTextField = "RoleName";
            this.roleDdl.DataValueField = "RoleId";
            this.roleDdl.DataBind();
        }

        private void InitTableTitle()
        {
            TableRow titleRow = new TableRow();
            TableCell blankCell = new TableCell();
            blankCell.CssClass = "cell";
            blankCell.Text = "CAT";
            blankCell.Font.Bold = true;
            TableCell blankCell2 = new TableCell();
            blankCell2.CssClass = "cell";
            blankCell2.Text = "Region";
            blankCell2.Font.Bold = true;
            TableCell cell1 = new TableCell();
            cell1.CssClass = "cell";
            cell1.Text = "已填总重要信息数";
            cell1.Font.Bold = true;
            titleRow.Cells.Add(cell1);
            TableCell cell2 = new TableCell();
            cell2.CssClass = "cell";
            cell2.Text = "应填总重要信息数";
            cell2.Font.Bold = true;
            titleRow.Cells.Add(cell2);
            TableCell cell3 = new TableCell();
            cell3.CssClass = "cell";
            cell3.Text = "已填重要客户数";
            cell3.Font.Bold = true;
            titleRow.Cells.Add(cell3);
            TableCell cell4 = new TableCell();
            cell4.CssClass = "cell";
            cell4.Text = "重要客户数";
            cell4.Font.Bold = true;
            titleRow.Cells.Add(cell4);
            TableCell cell5 = new TableCell();
            cell5.CssClass = "cell";
            cell5.Text = "已填客户数";
            cell5.Font.Bold = true;
            titleRow.Cells.Add(cell5);
            TableCell cell6 = new TableCell();
            cell6.CssClass = "cell";
            cell6.Text = "更新次数";
            cell6.Font.Bold = true;
            titleRow.Cells.Add(cell6);
            titleRow.Cells.Add(blankCell);
            titleRow.Cells.Add(blankCell2);
            titleRow.Cells.Add(cell1);
            titleRow.Cells.Add(cell2);
            titleRow.Cells.Add(cell3);
            titleRow.Cells.Add(cell4);
            titleRow.Cells.Add(cell5);
            titleRow.Cells.Add(cell6);
            this.KPISumTable.Rows.Add(titleRow);
        }

        private bool IsExistItem(ListItem tmpItem, ListBox tmpList)
        {
            for (int i = 0; i < tmpList.Items.Count; i++)
            {
                if (tmpItem.Value == tmpList.Items[i].Value)
                {
                    return true;
                }
            }
            return false;
        }

        private void lkbDown_Click(object sender, EventArgs e)
        {
            this.GetUserCountTeam();
            DataTable dt = new DataTable();
            StringWriter sw = new StringWriter();
            sw.Write("CAT,");
            sw.Write("Region,");
            sw.Write("已填重要信息数,");
            sw.Write("重要信息数,");
            sw.Write("已填重要客户数,");
            sw.Write("重要客户数,");
            sw.Write("已填客户数,");
            sw.Write("更新次数\n");
            for (int ii = 0; ii < this.KPISumTable.Rows.Count; ii++)
            {
                for (int jj = 0; jj < 8; jj++)
                {
                    if (jj == 7)
                    {
                        sw.Write(this.KPISumTable.Rows[ii].Cells[jj].Text + "\n");
                    }
                    else
                    {
                        sw.Write(this.KPISumTable.Rows[ii].Cells[jj].Text + ",");
                    }
                }
            }
            sw.Close();
            base.Response.AddHeader("Content-Disposition", "attachment; filename=CustomerInfo" + DateTime.Now.Millisecond.ToString() + ".csv");
            base.Response.ContentType = "application/ms-excel";
            base.Response.ContentEncoding = Encoding.GetEncoding("GB2312");
            base.Response.Write(sw);
            base.Response.End();
        }

        protected override void OnInit(EventArgs e)
        {
            this.InitializeComponent();
            base.OnInit(e);
            this.Principal = this.Context.User as UserPrincipal;
        }

        private void Page_Load(object sender, EventArgs e)
        {
            if (this.Principal.SysUser.IsAdmin == 0)
            {
                throw new ApplicationException(string.Format("User: {0} not has privilege to access this page.", this.Principal.SysUser.LoginName));
            }
            if (!base.IsPostBack)
            {
                this.InitPage();
            }
        }

        private void searchBtn_Click(object sender, EventArgs e)
        {
            this.InitTableTitle();
            for (int i = 0; i < this.catLb.Items.Count; i++)
            {
                for (int x = 0; x < this.provinceLb.Items.Count; x++)
                {
                    Guid[] customerIdAry = ManageCustomer.GetCustomerIdAryInCustomerBasicInfo(new Guid(this.catLb.Items[i].Value), new Guid(this.provinceLb.Items[x].Value), new Guid("06BA8C26-B1C9-4415-A6EC-1CF5CE99BF15"));
                    int updateCount_Inspirit = 0;
                    int userCustomerInfoCount = 0;
                    for (int j = 0; j < customerIdAry.Length; j++)
                    {
                        int emptyCount = 0;
                        CustomerBasicInfo customerBasicInfo = ManageCustomer.GetCustomerBasicInfoViaId(customerIdAry[j]);
                        emptyCount = (customerBasicInfo.Name == "") ? emptyCount : (emptyCount + 1);
                        emptyCount = (customerBasicInfo.Gender.Trim() == "") ? emptyCount : (emptyCount + 1);
                        emptyCount = (customerBasicInfo.Title == "") ? emptyCount : (emptyCount + 1);
                        emptyCount = (customerBasicInfo.MailAdd == "") ? emptyCount : (emptyCount + 1);
                        emptyCount = (customerBasicInfo.Level == 0) ? emptyCount : (emptyCount + 1);
                        emptyCount = (customerBasicInfo.Depart == "") ? emptyCount : (emptyCount + 1);
                        emptyCount = (customerBasicInfo.CustomerDefId.ToString() == "11111111-1111-1111-1111-111111111111") ? emptyCount : (emptyCount + 1);
                        emptyCount = ManageProduct.IsExitProductInCustomerProductViaId(customerBasicInfo.CustomerId) ? (emptyCount + 1) : emptyCount;
                        if (ManageCustomer.IsExistSameCoustomerPersonalInfo(customerIdAry[j]))
                        {
                            CustomerPersonalInfo customerPersonalInfo = ManageCustomer.GetCustomerPersonalInfoViaId(customerIdAry[j]);
                            emptyCount = (customerPersonalInfo.BirthDate.ToString() == "1800-1-1 0:00:00") ? emptyCount : (emptyCount + 1);
                            emptyCount = (customerPersonalInfo.BirthPlace == "\0\0\0\0") ? emptyCount : (emptyCount + 1);
                            emptyCount = (customerPersonalInfo.FamilyAdd == "\0\0\0\0") ? emptyCount : (emptyCount + 1);
                            emptyCount = (customerPersonalInfo.RelocationAdd == "\0\0\0\0") ? emptyCount : (emptyCount + 1);
                            emptyCount = (customerPersonalInfo.Mobile == "\0\0\0\0") ? emptyCount : (emptyCount + 1);
                            emptyCount = (customerPersonalInfo.Weight == "\0\0\0\0") ? emptyCount : (emptyCount + 1);
                            emptyCount = (customerPersonalInfo.Height == "\0\0\0\0") ? emptyCount : (emptyCount + 1);
                            emptyCount = (customerPersonalInfo.SpecicalHobbies == "\0\0\0\0") ? emptyCount : (emptyCount + 1);
                        }
                        if (ManageCheckUser.IsExistCustomerPreferenceInfoViaId(customerIdAry[j]))
                        {
                            emptyCount++;
                        }
                        if (ManageCustomer.IsExistSameCoustomerHealthInfo(customerIdAry[j]))
                        {
                            CustomerHealth customerHealth = ManageCustomer.GetCustomerHealthViaId(customerIdAry[j]);
                            emptyCount = (customerHealth.HealthStatus == 3) ? emptyCount : (emptyCount + 1);
                            emptyCount = (customerHealth.Eyesight == 3) ? emptyCount : (emptyCount + 1);
                            emptyCount = (customerHealth.MajorOperation == "\0\0\0\0") ? emptyCount : (emptyCount + 1);
                            emptyCount = (customerHealth.SpecialDisease == "\0\0\0\0") ? emptyCount : (emptyCount + 1);
                            emptyCount = (customerHealth.Allergy == "\0\0\0\0") ? emptyCount : (emptyCount + 1);
                        }
                        if (ManageCustomer.IsExistSameCoustomerCostumeInfo(customerIdAry[j]))
                        {
                            CustomerCostumeInfo customerCostumeInfo = ManageCustomer.GetCustomerCostumeInfoViaId(customerIdAry[j]);
                            emptyCount = (customerCostumeInfo.BrandPre == "\0\0\0\0") ? emptyCount : (emptyCount + 1);
                            emptyCount = (customerCostumeInfo.HipMeasurement == "\0\0\0\0") ? emptyCount : (emptyCount + 1);
                            emptyCount = (customerCostumeInfo.NeckMeasurement == "\0\0\0\0") ? emptyCount : (emptyCount + 1);
                            emptyCount = (customerCostumeInfo.ShoesSize == "\0\0\0\0") ? emptyCount : (emptyCount + 1);
                        }
                        if (ManageCustomer.IsExistSameCustomerStudyExperienceInfo(customerIdAry[j]))
                        {
                            emptyCount++;
                        }
                        if (ManageCustomer.IsExistSameCustomerWorkExperienceInfo(customerIdAry[j]))
                        {
                            emptyCount++;
                        }
                        if (ManageCustomer.IsExistSameCustomerASBContractInfo(customerIdAry[j]))
                        {
                            emptyCount++;
                        }
                        if (ManageCustomer.IsExistSameCustomerEVMeetingInfo(customerIdAry[j]))
                        {
                            emptyCount++;
                        }
                        if (ManageCustomer.IsExistSameCustomerVisitingAbroadInfo(customerIdAry[j]))
                        {
                            emptyCount++;
                        }
                        if (ManageCustomer.IsExistSameCustomerASBEventsInfo(customerIdAry[j]))
                        {
                            emptyCount++;
                        }
                        if (ManageCustomer.IsExistSameCustomerEventsInfo(customerIdAry[j]))
                        {
                            emptyCount++;
                        }
                        if (ManageCustomer.IsExistSameCustomerResponsibleStaffInfo(customerIdAry[j]))
                        {
                            emptyCount++;
                        }
                        if (ManageCustomer.IsExistSameCustomerASBReceptionInfo(customerIdAry[j]))
                        {
                            emptyCount++;
                        }
                        userCustomerInfoCount += emptyCount;
                        updateCount_Inspirit += this.GetCustomerUpdateNum(customerIdAry[j]);
                    }
                    int userImportCustomerNumCount = 0;
                    int userImportCustomerNumAllCount = 0;
                    int userCustomerNumAllCount = 0;
                    ArrayList companyIdAry = new ArrayList();
                    if (customerIdAry.Length > 0)
                    {
                        for (int s = 0; s < customerIdAry.Length; s++)
                        {
                            int isExist = 0;
                            Guid tmpId = new Guid();
                            tmpId = ManageCheckUser.GetCompanyIdViaCustomerId(customerIdAry[s]);
                            for (int y = 0; y < companyIdAry.Count; y++)
                            {
                                if (((Guid) companyIdAry[y]) == tmpId)
                                {
                                    isExist = 1;
                                }
                            }
                            if (isExist == 0)
                            {
                                companyIdAry.Add(tmpId);
                            }
                        }
                        for (int z = 0; z < customerIdAry.Length; z++)
                        {
                            for (int w = 0; w < companyIdAry.Count; w++)
                            {
                                if (ManageCheckUser.IsExistImportCustomerInKPI((Guid) companyIdAry[w], ManageCheckUser.GetCustomerNameViaCustomerId(customerIdAry[z])))
                                {
                                    userImportCustomerNumCount++;
                                }
                            }
                        }
                    }
                    for (int v = 0; v < companyIdAry.Count; v++)
                    {
                        int tmpImportCustomerNumAllCount = ManageCheckUser.GetImportCustomerCountViaIdInOrgTree((Guid) companyIdAry[v]);
                        userImportCustomerNumAllCount += tmpImportCustomerNumAllCount;
                    }
                    userCustomerNumAllCount = customerIdAry.Length;
                    double fillInInfoCount = 0.0;
                    double updateCount = 0.0;
                    if (customerIdAry.Length > 0)
                    {
                        fillInInfoCount = Math.Round(Convert.ToDouble(userCustomerInfoCount), 2);
                        updateCount = Math.Round(Convert.ToDouble(updateCount_Inspirit), 2);
                    }
                    KPI sumKPI = new KPI();
                    sumKPI.FillInInfoCount = fillInInfoCount;
                    sumKPI.FillInImportCustomerCount = userImportCustomerNumCount;
                    sumKPI.AllImportCustomerCount = userImportCustomerNumAllCount;
                    sumKPI.AllCustomerCount = userCustomerNumAllCount;
                    sumKPI.UpdateCount_Inspirit = updateCount;
                    TableRow itemRow = new TableRow();
                    TableCell itemCell = new TableCell();
                    TableCell itemCellP = new TableCell();
                    itemCell.CssClass = "cell";
                    itemCell.Width = Unit.Pixel(0x23);
                    itemCell.Text = this.catLb.Items[i].Text;
                    itemRow.Cells.Add(itemCell);
                    itemCellP.CssClass = "cell";
                    itemCellP.Width = Unit.Pixel(40);
                    itemCellP.Text = this.provinceLb.Items[x].Text;
                    itemRow.Cells.Add(itemCellP);
                    TableCell blankItemCell1 = new TableCell();
                    blankItemCell1.CssClass = "cell";
                    blankItemCell1.Width = Unit.Pixel(50);
                    blankItemCell1.Text = sumKPI.FillInInfoCount.ToString();
                    itemRow.Cells.Add(blankItemCell1);
                    TableCell blankItemCell2 = new TableCell();
                    blankItemCell2.CssClass = "cell";
                    blankItemCell2.Width = Unit.Pixel(50);
                    blankItemCell2.Text = Convert.ToString((int) (sumKPI.AllCustomerCount * 0x23));
                    itemRow.Cells.Add(blankItemCell2);
                    TableCell blankItemCell3 = new TableCell();
                    blankItemCell3.CssClass = "cell";
                    blankItemCell3.Width = Unit.Pixel(50);
                    blankItemCell3.Text = sumKPI.FillInImportCustomerCount.ToString();
                    itemRow.Cells.Add(blankItemCell3);
                    TableCell blankItemCell4 = new TableCell();
                    blankItemCell4.CssClass = "cell";
                    blankItemCell4.Width = Unit.Pixel(50);
                    blankItemCell4.Text = this.GetImportCustomerCountNumViaCustomerCompany(new Guid(this.catLb.Items[i].Value), new Guid(this.provinceLb.Items[x].Value)).ToString();
                    itemRow.Cells.Add(blankItemCell4);
                    TableCell blankItemCell5 = new TableCell();
                    blankItemCell5.CssClass = "cell";
                    blankItemCell5.Width = Unit.Pixel(50);
                    blankItemCell5.Text = sumKPI.AllCustomerCount.ToString();
                    itemRow.Cells.Add(blankItemCell5);
                    TableCell blankItemCell6 = new TableCell();
                    blankItemCell6.CssClass = "cell";
                    blankItemCell6.Width = Unit.Pixel(50);
                    blankItemCell6.Text = sumKPI.UpdateCount_Inspirit.ToString();
                    itemRow.Cells.Add(blankItemCell6);
                    this.KPISumTable.Rows.Add(itemRow);
                }
            }
        }
    }
}

